<template>
  <div class="pageBox">
    <head-component title="我的订单"></head-component>
    <van-tabs
      v-model:active="active"
      @change="tabChange"
      title-inactive-color="#333333"
      title-active-color="#E00B12"
      line-width="20px"
    >
      <van-tab title="全部"></van-tab>
      <van-tab title="待付款"></van-tab>
      <van-tab title="待发货"></van-tab>
      <van-tab title="待收货"></van-tab>
      <van-tab title="已完成"></van-tab>
    </van-tabs>
    <div class="list">
      <div class="listItem" @click="goDetails">
        <div class="itemTop flex-between">
          <p>订单编号：123445618768878</p>
          <span>待付款</span>
        </div>
        <div class="goodsInfo flex-between">
          <img class="infoLeft" src="../../image/home/banner.png" alt="" />
          <div class="infoRight">
            <div class="infoTitle">小怡室集 衣物留香珠220g</div>
            <div class="sku flex-row">
              <div class="skuItem">规格：L</div>
            </div>
            <div class="price">￥39.9</div>
            <div class="number">x 1</div>
          </div>
        </div>
        <div class="totalBox flex-row">
          <p>共1件商品，合计</p>
          <span>￥39.90</span>
        </div>
        <div class="btnBox flex-row">
          <button class="closeBtn" @click.stop="onCloseBtn">取消订单</button>
          <button class="payBtn">付款</button>
          <button class="tipsBtn">提醒发货</button>
          <button class="closeBtn" @click.stop="goLogistics">查看物流</button>
          <button class="payBtn">确认收货</button>
        </div>
      </div>
    </div>
    <van-popup v-model:show="show" position="bottom" round>
      <div class="popupBox">
        <img
          class="popupClose"
          src="@/image/my/popupClose.png"
          alt=""
          @click="show = false"
        />
        <div class="title flex-center">请选择原因</div>
        <div class="tips flex-center">
          订单一旦取消，无法恢复，金额积分将原路返还
        </div>
        <div class="reason">
          <div
            class="reasonItem flex-between"
            v-for="item in closeReason"
            :key="item.id"
            @click="onReasonItem(item)"
          >
            <div
              :class="[
                item.status ? 'reasonItemRActive reasonItemR' : 'reasonItemR',
              ]"
            >
              {{ item.title }}
            </div>
            <img :src="item.chooseImg" alt="" v-if="!item.status" />
            <img :src="item.choosedImg" alt="" v-else />
          </div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script type="text/ecmascript-6">
import { defineComponent, ref } from "vue";
import headComponent from "../../components/headComponent.vue";
import router from "../../router";

export default defineComponent({
  components: {
    headComponent,
  },
  setup() {
    const active = ref(0);

    const show = ref(false);

    const reasonId = ref(1);
    const closeReason = ref([
      {
        id: 1,
        title: "收货地址填错了",
        status: true,
        chooseImg: require("@/image/my/closeChoose.png"),
        choosedImg: require("@/image/my/closeChoosed.png"),
      },
      {
        id: 2,
        title: "忘记支付密码/余额不足",
        status: false,
        chooseImg: require("@/image/my/closeChoose.png"),
        choosedImg: require("@/image/my/closeChoosed.png"),
      },
      {
        id: 3,
        title: "无法正常支付",
        status: false,
        chooseImg: require("@/image/my/closeChoose.png"),
        choosedImg: require("@/image/my/closeChoosed.png"),
      },
      {
        id: 4,
        title: "不想买了",
        status: false,
        chooseImg: require("@/image/my/closeChoose.png"),
        choosedImg: require("@/image/my/closeChoosed.png"),
      },
      {
        id: 5,
        title: "其他原因",
        status: false,
        chooseImg: require("@/image/my/closeChoose.png"),
        choosedImg: require("@/image/my/closeChoosed.png"),
      },
    ]);

    function tabChange(name) {
      console.log(name, active.value);
    }

    // 取消订单
    function onCloseBtn() {
      show.value = true;
    }

    function onReasonItem(param) {
      closeReason.value.forEach((item) => {
        item.status = false;
        if (item.id == param.id) {
          item.status = true;
          reasonId.value = item.id;
          show.value = false;
        }
      });
    }

    function goDetails() {
      router.push({
        path: "/orderDetails",
      })
    }

    function goLogistics() {
        router.push({
        path: "/logistics",
      })
    }

    return {
      active,
      show,
      closeReason,
      reasonId,
      tabChange,
      onCloseBtn,
      onReasonItem,
      goDetails,
      goLogistics,
    };
  },
});
</script>

<style scoped lang="less">
.pageBox {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-top: 88px;
  .list {
    .listItem {
      background-color: #fff;
      margin-top: 20px;
      padding: 30px;
      .itemTop {
        p {
          font-size: 24px;
          font-weight: 400;
          color: #999999;
        }
        span {
          font-size: 24px;
          font-weight: 400;
          color: #e00b12;
        }
      }
      .goodsInfo {
        margin-top: 40px;
        width: 100%;
        .infoLeft {
          width: 168px;
          height: 168px;
          border-radius: 10px;
        }
        .infoRight {
          width: 100%;
          padding-left: 20px;
          .infoTitle {
            font-size: 28px;
            font-weight: 500;
            color: #333333;
          }
          .sku {
            flex-wrap: wrap;
            margin-top: 20px;
            .skuItem {
              font-size: 26px;
              font-weight: 400;
              color: #999999;
              margin-right: 14px;
            }
          }
          .price {
            text-align: right;
            font-size: 26px;
            font-weight: 500;
            color: #333333;
          }
          .number {
            text-align: right;
            font-size: 26px;
            font-weight: 400;
            color: #999999;
          }
        }
      }
      .totalBox {
        margin-top: 30px;
        justify-content: flex-end;
        p {
          font-size: 26px;
          font-weight: 400;
          color: #999999;
        }
        span {
          font-size: 26px;
          font-weight: 400;
          color: #e00b12;
        }
      }
      .btnBox {
        margin-top: 61px;
        justify-content: flex-end;
        button {
          width: 144px;
          height: 56px;
          border-radius: 10px;
          font-size: 24px;
          font-weight: 400;
          margin-left: 39px;
        }
        .closeBtn {
          color: #999999;
          background: #ffffff;
          border: 1px solid #cccccc;
        }
        .payBtn {
          color: #ffffff;
          background: linear-gradient(270deg, #b30b11 0%, #f50811 100%);
          border: none;
        }
        .tipsBtn {
          color: #e00b12;
          background: #fff;
          border: 1px solid #e00b12;
        }
      }
    }
  }
  .popupBox {
    padding: 46px 39px 34px 40px;
    position: relative;
    .popupClose {
      width: 48px;
      height: 48px;
      position: absolute;
      right: 19px;
      top: 19px;
    }
    .title {
      font-size: 36px;
      font-weight: 500;
      color: #333333;
    }
    .tips {
      font-size: 26px;
      font-weight: 400;
      color: #e00b12;
      margin-top: 16px;
      margin-bottom: 7px;
    }
    .reason {
      .reasonItem {
        margin-top: 72px;
        .reasonItemR {
          font-size: 30px;
          font-weight: 400;
          color: #333333;
        }
        .reasonItemRActive {
          font-weight: bold;
        }
        img {
          width: 40px;
          height: 40px;
        }
      }
    }
  }
}
</style>